package com.lanyun.auth.domain.authRolePermission.impl;


import com.lanyun.auth.basic.entity.AuthRolePermission;
import com.lanyun.auth.basic.service.AuthRolePermissionService;
import com.lanyun.auth.controller.admin.authRolePermission.vo.AuthRolePermissionRequestVO;
import com.lanyun.auth.domain.authRolePermission.AuthRolePermissionDomainService;
import com.lanyun.web.enums.IsDeletedFlagEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 权限领域service
 *
 * @Author Jqcc
 * @Version 1.0
 * @Data 2024/3/12
 */
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {

    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionRequestVO authRolePermissionRequestVO) {

        List<AuthRolePermission> authRolePermissionList = new LinkedList<>();
        Long roleId = authRolePermissionRequestVO.getRoleId();
        authRolePermissionRequestVO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getVal());
            authRolePermissionList.add(authRolePermission);
        });

        Integer count = authRolePermissionService.insertBatch(authRolePermissionList);

        return count > 0;
    }
}
